﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ListaTelefonicaMEM.Classes
{
    public static class TString
    {
        public static string GetTelefone(this string prInput)
        {
            string res = null;

            foreach (char c in prInput)
            {
                if (char.IsDigit(c))
                {
                    res += c.ToString();
                }
            }

            return res;
        }

        public static string SetMaskTelefone(this string prInput)
        {
            prInput = prInput.PadLeft(11, '0');

            string res;

            res = "(" + prInput.Substring(0, 3) + ") ";
            res += prInput.Substring(3, 4) + "-";
            res += prInput.Substring(7, 4);

            return res;
        }

        public static bool isTelefone(this string prInput)
        {
            bool res = true;

            foreach (char item in prInput)
            {
                if (!char.IsDigit(item))
                {
                    res = false;
                    break;
                }
            }

            return res;
        }

        public static bool isEmptyStr(this string prInput)
        {
            bool res = true;
            
            foreach (char item in prInput)
            {
                if (item != ' ')
                {
                    res = false;
                    break;
                }
            }
            return res;
        }

        public static string GetDigitsString(this string prInput, int prOutputLength, char prChar = '0')
        {
            string res = null;

            foreach (char item in prInput)
            {
                if (char.IsDigit(item))
                {
                    res += item.ToString();
                }
            }

            return res.PadLeft(prOutputLength, prChar);

        }
    }
}
